﻿Imports System.Data.OleDb

Public Class addTutor
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Sub btn_AddTutor_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btn_AddTutor.Click
        Dim myGUID As New System.Guid
        myGUID = Guid.NewGuid()
        Dim newFileName = myGUID.ToString() + ".jpg"
        If f_Picture.HasFile Then
            Dim picLocationOnServerHardDisk = Request.MapPath("Pictures") & "/" & newFileName
            f_Picture.SaveAs(picLocationOnServerHardDisk)
        End If

        Dim oleDbConn As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("TutorsConnectionString").ConnectionString)
        Dim SqlString As String = "Insert into tbl_Tutors(Title,FirstName,Surname,Picture,Location,Subject,HourlyRate,Qualifications,Experience,Availability,EmailAddress) Values (@f1,@f2,@f3,@f4,@f5,@f6,@f7,@f8,@f9,@f10,@f11)"
        Dim cmd As OleDbCommand = New OleDbCommand(SqlString, oleDbConn)
        cmd.CommandType = CommandType.Text

        cmd.Parameters.AddWithValue("@f1", ddl_Title.SelectedValue)
        cmd.Parameters.AddWithValue("@f2", tb_FirstName.Text)
        cmd.Parameters.AddWithValue("@f3", tb_Surname.Text)
        cmd.Parameters.AddWithValue("@f4", "Pictures/" & newFileName)
        cmd.Parameters.AddWithValue("@f5", tb_Location.Text)
        cmd.Parameters.AddWithValue("@f6", tb_Subject.Text)
        cmd.Parameters.AddWithValue("@f7", tb_HourlyRate.Text)
        cmd.Parameters.AddWithValue("@f8", tb_Qualifications.Text)
        cmd.Parameters.AddWithValue("@f9", tb_Experience.Text)
        cmd.Parameters.AddWithValue("@f10", rbl_Availability.SelectedValue)
        cmd.Parameters.AddWithValue("@f11", tb_EmailAddress.Text)
        oleDbConn.Open()
        cmd.ExecuteNonQuery()
        Response.Redirect("tutorConfirmation.aspx")
    End Sub
End Class